package com.Service.Impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Dao.BaseDaoI;
import com.Entity.Users;
import com.Service.UsersService;
@Service(value="usersservice")
public class UsersServiceImpl extends BaseServiceImpl<Users> implements UsersService{

	@Autowired
	private BaseDaoI<Users> usersdao;
	
	List<Users> userlist=new ArrayList<Users>();
	Users user=new Users();
	@Override
	public List<Users> CheckLogin(String userName,String password) {
		
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userName", userName);
		params.put("password", password);
		String hql = "from Users t where t.userName = :userName and t.password = :password";	
		userlist=this.usersdao.find(hql, params);
		return userlist;
	}



	@Override
	public Users findByUserName(String userName) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userName", userName);
		String hql = "from Users t where t.userName = :userName";
		return (Users) find(hql, params);
	}

	@Override
	public Users findByUserID(int userId){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		String hql = "from Users t where t.userId = :userId";
		userlist=this.usersdao.find(hql, params);
		if(userlist.isEmpty()){
			return null;
		}
		return userlist.get(0);
		
	}
	
	
	@Override
	public List<Users> findByPrivateEmail(String PrivateEmail) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("PrivateEmail", PrivateEmail);
		String hql = "from Users t where t.privateEmail = :PrivateEmail";
		userlist=this.usersdao.find(hql, params);
		return userlist;
	}

}
